import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { WxUserVo, WxUserForm, WxUserQuery, ChatUserVo, CustomerServiceForm, CustomerServiceVo } from '@/api/wxuser/types';

/**
 * 查询微信用户信息列表
 * @param query
 * @returns {*}
 */

export const listWxUser = (query?: WxUserQuery): AxiosPromise<WxUserVo[]> => {
  return request({
    url: '/lawyer/wxUser/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询微信用户信息详细
 * @param wxUserId
 */
export const getWxUser = (wxUserId: string | number): AxiosPromise<WxUserVo> => {
  return request({
    url: '/lawyer/wxUser/' + wxUserId,
    method: 'get'
  });
};

/**
 * 新增微信用户信息
 * @param data
 */
export const addWxUser = (data: WxUserForm) => {
  return request({
    url: '/lawyer/saveWxUser',
    method: 'post',
    data: data
  });
};

/**
 * 修改微信用户信息
 * @param data
 */
export const updateWxUser = (data: WxUserForm) => {
  return request({
    url: '/lawyer/updateWxUser',
    method: 'post',
    data: data
  });
};

/**
 * 删除微信用户信息
 * @param wxUserId
 */
export const delWxUser = (wxUserId: string | number | Array<string | number>) => {
  return request({
    url: '/lawyer/removeWxUser/' + wxUserId,
    method: 'delete'
  });
};

export const resetPwd = (wxUserId: string | number, password: string) => {
  const data = {
    wxUserId,
    password
  };
  return request({
    url: '/lawyer/wxUser/resetPassword',
    method: 'post',
    headers: {
      isEncrypt: false,
      repeatSubmit: false
    },
    data: data
  });
};

/**
 * 查询客服信息
 */
export const getSupport = (): AxiosPromise<CustomerServiceVo> => {
  return request({
    url: '/lawyer/wxUser/getSupport',
    method: 'get'
  });
};

export const saveSupport = (data: CustomerServiceVo) => {
  return request({
    url: '/lawyer/wxUser/saveSupport',
    method: 'post',
    data: data
  });
};

export const getListChatUser = (): AxiosPromise<ChatUserVo[]> => {
  return request({
    url: '/lawyer/wxUser/listChatUser',
    method: 'get'
  });
};

export const getListAllChatUser = (): AxiosPromise<ChatUserVo[]> => {
  return request({
    url: '/lawyer/wxUser/listAllChatUser',
    method: 'get'
  });
};

export const lockUser = (wxUserId: string | number) => {
  const data = {
    wxUserId
  };
  return request({
    url: '/lawyer/wxUser/lockedUser',
    method: 'post',
    headers: {
      isEncrypt: false,
      repeatSubmit: false
    },
    data: data
  });
};

export const unlockUser = (wxUserId: string | number) => {
  const data = {
    wxUserId
  };
  return request({
    url: '/lawyer/wxUser/unlockUser',
    method: 'post',
    headers: {
      isEncrypt: false,
      repeatSubmit: false
    },
    data: data
  });
};

export const saveTag = (data: WxUserForm) => {
  return request({
    url: '/lawyer/wxUser/saveTag',
    method: 'post',
    data: data
  });
};
